 //
//  huiyuanDetailsViewController.m
//  daogouApp
//
//  Created by panquanReabam.com on 15-6-2.
//  Copyright (c) 2015年 jiezsoft.com. All rights reserved.
//

#import "kucunViewController.h"
#import "HttpRequest.h"
#import "JSONKit.h"
#import "HAODEsingleton.h"
#import "ProductView.h"
#import "UIViewExt.h"
#import "RDVTabBarController.h"
#import "MJRefresh.h"
#import "huiyuanDetailsCell.h"

#import "UIImage+RTTint.h"
#import "UIButton+WebCache.h"
#import "BusinessCheckVouchAddViewController.h"
#import "BusinessOrderExtAddViewController.h"
#import "BusinessWhsInAddViewController.h"
@interface kucunViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UITextViewDelegate>
@property(nonatomic,strong)NSString*DocType;

@end

@implementation kucunViewController


{   UIView*beizhuView;
    UILabel *line;
    UIScrollView*myscrollView;
    HAODEsingleton* commdity;
    UIImageView* imageview;
    UILabel *lineLabel1;
    ProductView *clothView;
    NSMutableArray*Memo;
    NSMutableArray*Integral;
    NSMutableArray*Amount;
    NSMutableArray*CreateDate;
    float lastContentOffset;
    UILabel *lineLabel111;
    UIButton*agreementBtn;
    UIButton*agreementBtn1;
    UIView*view11;
    UIView*view1;
    NSMutableArray*Gram;
    NSMutableArray*scanStockResultArray;
    NSMutableArray*InDate;
    NSMutableArray*currentSpecId;
    NSMutableArray*itemId;
    NSMutableArray*itemcode;
    NSMutableArray*ItemName;
    NSMutableArray*how;
    NSMutableArray* specName;
    NSMutableArray* Price;
    NSMutableArray* ImageUrl;
    UILabel*name;
    UITextView* tv;
    UILabel * label;
    UIImageView*imagess;
    UIButton*buyBtn1;
    UIButton*buyBtn2;
    UITextField*xianjinTextFied;
    UIButton*hejibuyBtn1;
    double sum1;
    UILabel*shu;
    UILabel* kucun;
}
@synthesize alt = alt;
-(void)BackAction:(UIButton *)sender{
    
     commdity.sx=@"sx";
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden=NO;
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
  
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
   
    commdity.whsName=@"";
    commdity.content=@"";
    commdity.leixin=@"";
    commdity.code=@"";
    commdity.status=@"";
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"扫描记录";
    
    
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor blackColor],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    
    
    
    _table.delegate=self;
    _table.dataSource=self;
    _table.separatorStyle=UITableViewCellSeparatorStyleNone;
    
    
    
    
    hejibuyBtn1=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-45, ScreenWidth*430/750, 45)];
//  [hejibuyBtn1 setTitle:[NSString stringWithFormat:@"合计 ¥ %@",@""] forState:UIControlStateNormal];
    hejibuyBtn1.backgroundColor=backColor;
    [hejibuyBtn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    hejibuyBtn1.alpha=0.8;
    [self.view addSubview:hejibuyBtn1];

    UIButton*tijiao=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*430/750, ScreenHeight-45, ScreenWidth*320/750, 45)];
    [tijiao setTitle:@"提交" forState:UIControlStateNormal];
    tijiao.backgroundColor=luseColor;
    [tijiao setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [tijiao addTarget:self action:@selector(tijiao:) forControlEvents:UIControlEventTouchUpInside];
    [tijiao setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:tijiao];
    
    [self add];
    
}
-(void)add{
      commdity=[HAODEsingleton shared];
    
    how= [[NSMutableArray alloc] init];
    ImageUrl= [[NSMutableArray alloc] init];
    currentSpecId= [[NSMutableArray alloc] init];
    ItemName= [[NSMutableArray alloc] init];
    Price = [[NSMutableArray alloc] init];
    itemId = [[NSMutableArray alloc] init];
    itemcode= [[NSMutableArray alloc] init];
    specName= [[NSMutableArray alloc] init];
    itemId=commdity.Itemid44;
    itemcode=commdity.ItemCode44;
    ItemName=commdity.ItemName44;
    ImageUrl=commdity.ImageUrl44;
    specName=commdity.specName44;
    Price=commdity.Price44;
    currentSpecId=commdity.currentSpecId44;
    how=commdity.how44;

    NSLog(@"-----------%@",commdity. ItemName44);
    
    

    [_table reloadData];
    
    if (commdity.ItemName44.count==0) {
        
        
        name=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        name.text= @"请搜索或者扫描商品开始服务！";
        name.textAlignment=NSTextAlignmentCenter;
        name.backgroundColor=[UIColor whiteColor];
        name.font= [UIFont systemFontOfSize:contenfot];
        [name setTextColor:[UIColor blackColor]];
        [self.view addSubview:name];
        

        
    }else {
        
        
        [name  removeFromSuperview];
        
         NSMutableArray*  sum=[[NSMutableArray alloc]init];
   
        for (int i=0; i<Price.count; i++) {
           
            NSString *typeCode1 = [Price objectAtIndex:i];
            NSString *isSingle1 = [how objectAtIndex:i];
           
            [sum addObject:[NSString stringWithFormat:@"%.2f",  [typeCode1 doubleValue]*[isSingle1 doubleValue]]];
        
        
        }

    
        
       NSNumber *sum11 = [sum valueForKeyPath:@"@sum.floatValue"];
        NSString*GoldPrice=[NSString stringWithFormat:@"%@",sum11];
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
         [self priceStr:formattedNumberString];
       

    }
    UIView*view111=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth,80/2)];
    view111.backgroundColor=zuiqianhuicolor;
    _table .tableHeaderView=view111;
    
    NSNumber *su = [how valueForKeyPath:@"@sum.floatValue"];
    
   kucun=[[UILabel alloc]initWithFrame:CGRectMake(15, 25/2, 250, 14)];
   kucun.text=[NSString stringWithFormat:@"共有 %@ 条扫描记录",su];
    kucun.textColor=shenhuicolor;
    kucun.font=[UIFont systemFontOfSize:14];
    [view111 addSubview:kucun];

    
    UIButton*shaixuanBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*590/750,  15/2, ScreenWidth*140/750,50/2)];
    [shaixuanBtn.layer setCornerRadius:2.0];
    [shaixuanBtn.layer setBorderWidth:0.5];
    [shaixuanBtn.layer setMasksToBounds:YES];
    [shaixuanBtn addTarget:self action:@selector(qingkong:) forControlEvents:UIControlEventTouchUpInside];
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){153/255.0,153/255.0, 153/255.0, 1.0   });
    [shaixuanBtn.layer setBorderColor:colorref2];//边框颜色
    //                [shaixuanBtn setTitle:@"     清空" forState:UIControlStateNormal];
    shaixuanBtn.titleLabel.font=[UIFont systemFontOfSize:contenfot];
    [shaixuanBtn setTitleColor:shenhuicolor forState:UIControlStateNormal];
    shaixuanBtn.titleLabel.textAlignment=NSTextAlignmentRight;
    //                [view addSubview:shaixuanBtn];
    
    
    UIButton*sxBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-40,20/2, 20, 20)];
    [sxBtn setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
    [sxBtn addTarget:self action:@selector(qingkong:) forControlEvents:UIControlEventTouchUpInside];
    [view111 addSubview:sxBtn];
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if (buttonIndex == 0) {
        
        
        ImageUrl= [[NSMutableArray alloc] init];
        itemId= [[NSMutableArray alloc] init];
        ItemName= [[NSMutableArray alloc] init];
        Price = [[NSMutableArray alloc] init];
        currentSpecId= [[NSMutableArray alloc] init];
        how = [[NSMutableArray alloc] init];
        specName = [[NSMutableArray alloc] init];
        itemcode = [[NSMutableArray alloc] init];
        [specName removeAllObjects];
        [ItemName removeAllObjects];
        [ImageUrl removeAllObjects];
        [Price removeAllObjects];
        [itemId removeAllObjects];
        [currentSpecId removeAllObjects];
        [how removeAllObjects];
        
        [itemcode removeAllObjects];
        commdity.ItemCode44=itemcode;
        commdity.ImageUrl44=ImageUrl;
        commdity.ItemName44=ItemName;
        commdity.Price44=Price;
        commdity.currentSpecId44=currentSpecId;
        commdity.how44=how;
        commdity.Itemid44=itemId;
        commdity.specName44=specName;
        commdity.how=@"sx";
       
         [self add];


        
    }
}

-(void)qingkong:(UIButton*)sender{
    UIAlertView*altss = [[UIAlertView alloc] initWithTitle:@"温馨提示 确认清空吗？" message:nil delegate:self cancelButtonTitle:@"确认" otherButtonTitles:@"取消",  nil];
    [altss show];
        
    

}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [ImageUrl count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    huiyuanDetailsCell* cell = (huiyuanDetailsCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"huiyuanDetailsCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    UIButton*jiantou = [[UIButton alloc]init];
    jiantou.frame = CGRectMake(0,0, 8, 13);
    [jiantou setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    
    //    cell.accessoryView = jiantou;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    
    [cell.imagebtn.layer setCornerRadius:2.0];
    [cell.imagebtn.layer setBorderWidth:0.3];
    [cell.imagebtn.layer setMasksToBounds:YES];
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0, 0, 0, 0.3 });
    [cell.imagebtn.layer setBorderColor:colorref2];//边框颜色
    [cell.imagebtn setImageWithURL:[NSURL URLWithString:[ImageUrl objectAtIndex:indexPath.row]]];
    //    [cell.imagebtn setImageWithURL:[NSURL URLWithString:[ImageUrl objectAtIndex:indexPath.row]]placeholderImage:nil];
    cell.imagebtn.frame=CGRectMake(ScreenWidth*30/750,  20,  170/2,  170/2);
    
    
    
    cell.CreateDate.text =[NSString stringWithFormat:@"%@%@",[ItemName objectAtIndex:indexPath.row],[itemcode objectAtIndex:indexPath.row]];
    cell.CreateDate.font=[UIFont systemFontOfSize:14];
    cell.CreateDate.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    cell.CreateDate.frame=CGRectMake(cell.imagebtn.right+10, 17.5, 520*ScreenWidth/750,32);
    cell.CreateDate.numberOfLines=0;

    
    
//    cell.Memo.text =[NSString stringWithFormat:@"库存 %@",[specName objectAtIndex:indexPath.row]];
//    cell.Memo.font=[UIFont systemFontOfSize:12];
//    cell.Memo.textColor=qianheicolor;
//    cell.Memo.frame=CGRectMake(ScreenWidth-150, cell.CreateDate.bottom, 135,12);
//    cell.Memo.textAlignment=NSTextAlignmentRight;
//
    
    
    
    NSString*GoldPrice=[NSString stringWithFormat:@"%@",[Price objectAtIndex:indexPath.row]];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];

    cell.Price.text =[NSString stringWithFormat:@"￥%@",  formattedNumberString];
    cell.Price.font=[UIFont systemFontOfSize:12];
    cell.Price.textColor=zhonghuiColor;
    cell.Price.frame=CGRectMake(cell.imagebtn.right+10, cell.CreateDate.bottom, 400*ScreenWidth/750,12);
    NSMutableAttributedString *AttributedStr2 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"￥%@",  formattedNumberString]];
    
    [AttributedStr2 addAttribute:NSFontAttributeName
     
                           value:[UIFont systemFontOfSize:12]
     
                           range:NSMakeRange(0, 1)];
    
    [AttributedStr2 addAttribute:NSForegroundColorAttributeName
     
                           value:zhonghuiColor
     
                           range:NSMakeRange(0, 1)];

    cell.Price.attributedText = AttributedStr2;
    
    
    
    UIImageView*shuimageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-180, 70, 165, 35)];
    shuimageview .image=[UIImage imageNamed:@"tianjias"];
    [cell.contentView addSubview:shuimageview];
    
//    cell.time=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 120, 30)];
    cell.time.text=[NSString stringWithFormat:@"%@",  [how objectAtIndex:indexPath.row]];
    cell.time.textColor=qianheicolor;
    cell.time.center=shuimageview.center;
    cell.time.textAlignment=NSTextAlignmentCenter;
    cell.time.font=[UIFont systemFontOfSize:16];
    [cell.contentView addSubview:cell.time];
    cell.how=[NSString stringWithFormat:@"%@",  [how objectAtIndex:indexPath.row]];
    UIButton*jian=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-180, 70, 30, 35)];
    jian.tag=indexPath.row;
    [jian addTarget:self action:@selector(jian:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:jian];
    
    UIButton*jia=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-50,70, 30, 35)];
    jia.tag=indexPath.row;
    [jia addTarget:self action:@selector(jia:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:jia];

    
    
    
    if (itemId.count !=indexPath.row+1) {
        UILabel *lineLabel11=[[UILabel alloc] initWithFrame:CGRectMake(15, 120-0.35, ScreenWidth-30, 0.35)];
        lineLabel11.backgroundColor=[UIColor groupTableViewBackgroundColor];;
        [cell.contentView addSubview:lineLabel11];
        
    }
    
    if (itemId.count ==indexPath.row+1) {
        UILabel *lineLabel11=[[UILabel alloc] initWithFrame:CGRectMake(0, 120-0.35, ScreenWidth, 0.35)];
        lineLabel11.backgroundColor=[UIColor groupTableViewBackgroundColor];
        [cell.contentView addSubview:lineLabel11];
        
    }
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 120;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 
    
    
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return  UITableViewCellEditingStyleDelete;
    
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}


-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

{
    
    return @"删除";
    
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    
    ImageUrl= [[NSMutableArray alloc] init];
    ItemName= [[NSMutableArray alloc] init];
    Price = [[NSMutableArray alloc] init];
    currentSpecId= [[NSMutableArray alloc] init];
    how = [[NSMutableArray alloc] init];
    itemId = [[NSMutableArray alloc] init];
    specName= [[NSMutableArray alloc] init];
    itemcode=[[NSMutableArray alloc]init];
    itemId = [NSMutableArray arrayWithArray:commdity.Itemid44];
    itemcode= [NSMutableArray arrayWithArray:commdity.ItemCode44];
    ItemName = [NSMutableArray arrayWithArray:commdity.ItemName44];
    ImageUrl = [NSMutableArray arrayWithArray:commdity.ImageUrl44];
    Price = [NSMutableArray arrayWithArray:commdity.Price44];
    currentSpecId = [NSMutableArray arrayWithArray:commdity.currentSpecId44];
    how = [NSMutableArray arrayWithArray:commdity.how44];
    specName= [NSMutableArray arrayWithArray:commdity.specName44];

    [itemId removeObjectAtIndex:indexPath.row];//从指定索引移除
    [itemcode removeObjectAtIndex:indexPath.row];//从指定索引移除

    [ImageUrl removeObjectAtIndex:indexPath.row];//从指定索引移除
    [currentSpecId removeObjectAtIndex:indexPath.row];//从指定索引移除
    [how removeObjectAtIndex:indexPath.row];//从指定索引移除
    [ItemName removeObjectAtIndex:indexPath.row];//从指定索引移除
    [Price removeObjectAtIndex:indexPath.row];//从指定索引移除
     [specName removeObjectAtIndex:indexPath.row];//从指定索引移除
    
    commdity.ItemCode44= itemcode;
     commdity.Itemid44= itemId;
    commdity.ItemName44= ItemName;
    commdity.ImageUrl44= ImageUrl;
    commdity.Price44= Price;
    commdity.currentSpecId44=currentSpecId;
    commdity.how44=how;
   
    commdity.specName44=specName;
    
    commdity.sx =@"sx";
   
    [_table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    [self add];
    
}
#pragma mark - Table view delegate









-(void)jia:(UIButton*)sender{
    
    UIButton* button=(UIButton * )sender;
    huiyuanDetailsCell* cell=(huiyuanDetailsCell* )button.superview.superview;
    
        int d;
        d= cell.time.text.intValue;
        d++;
    NSLog(@"---------%ld",sender.tag);
    
    
    NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:how];
    [mutableArray replaceObjectAtIndex:sender.tag withObject:[NSString stringWithFormat:@"%d", d]];
    how = mutableArray;//now the array has been "updated"
    commdity.how44=[how mutableCopy];
    cell.time.text=[NSString stringWithFormat:@"%d", d];
    
    [self heji];
}
-(void)heji{
    [name  removeFromSuperview];
    
    NSMutableArray*  sum=[[NSMutableArray alloc]init];
    
    for (int i=0; i<Price.count; i++) {
        
        NSString *typeCode1 = [Price objectAtIndex:i];
        NSString *isSingle1 = [how objectAtIndex:i];
        
        [sum addObject:[NSString stringWithFormat:@"%.2f",  [typeCode1 doubleValue]*[isSingle1 doubleValue]]];
        
        
    }

    NSNumber *sum11 = [sum valueForKeyPath:@"@sum.floatValue"];
    NSString*GoldPrice=[NSString stringWithFormat:@"%@",sum11];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
    [self priceStr:formattedNumberString];
    
    NSNumber *su = [how valueForKeyPath:@"@sum.floatValue"];
    kucun.text=[NSString stringWithFormat:@"共有 %@ 条扫描记录",su];
}

-(void)jian:(UIButton*)sender{
 
    UIButton* button=(UIButton * )sender;
    huiyuanDetailsCell* cell=(huiyuanDetailsCell* )button.superview.superview;
   
    if ([cell.time.text isEqualToString:@"1"]) {
        [self showAlertMessage:@"数量不能为 0 件！"];
    
    
    }else{
    
    int d;
    d= cell.time.text.intValue;
    d--;
    NSLog(@"---------%ld",sender.tag);
    
    
    NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:how];
    [mutableArray replaceObjectAtIndex:sender.tag withObject:[NSString stringWithFormat:@"%d", d]];
    how = mutableArray;//now the array has been "updated"
    commdity.how44=[how mutableCopy];
    cell.time.text=[NSString stringWithFormat:@"%d", d];
        
    [self heji];
    }
    
    
}


-(void)priceStr:(NSString *)str {
    
    [hejibuyBtn1 setTitle:[NSString stringWithFormat:@"  合计 ￥%@",str] forState:UIControlStateNormal];
    NSMutableAttributedString *AttributedStr1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"  合计 ￥%@",str]];
    
    [AttributedStr1 addAttribute:NSFontAttributeName
     
                           value:[UIFont systemFontOfSize:14.0]
     
                           range:NSMakeRange(0, 6)];
    
    [AttributedStr1 addAttribute:NSForegroundColorAttributeName
     
                           value:[UIColor whiteColor]
     
                           range:NSMakeRange(0, 6)];
    
    
    hejibuyBtn1.titleLabel.attributedText = AttributedStr1;
    
}



- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}
-(void)textViewDidChange:(UITextView *)textView
{
    //        self.examineText =  textView.text;
    if (textView.text.length == 0) {
        [imagess removeFromSuperview];
        
        imagess=[[UIImageView alloc]initWithFrame:CGRectMake(15, 8, 51/3, 51/3)];
        imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        [tv addSubview:imagess];
        label.text = @"备注";
        
    }else{
        [imagess removeFromSuperview];
        label.text = @"";
    }
}


-(void)chooseBtn1:(UIButton*)sender{
    
    [view11 removeFromSuperview];
    [view1 removeFromSuperview];
    commdity.ItemCode44= itemcode;
    commdity.Itemid44= itemId;
    commdity.ItemName44= ItemName;
    commdity.ImageUrl44= ImageUrl;
    commdity.Price44= Price;
    commdity.currentSpecId44=currentSpecId;
    commdity.how44=how;
    commdity.specName44=specName;
    commdity.whsName=@"";
    commdity.content=@"";
    commdity.leixin=@"";
    commdity.code=@"";
    
    BusinessWhsInAddViewController *detailViewController = [[BusinessWhsInAddViewController alloc] init];
    detailViewController.titleName=@"确认陈列";
    detailViewController.Whs=@"Shelf";
    
    [self.navigationController pushViewController:detailViewController animated:YES];
    
}

-(void)chooseBtn3:(UIButton*)sender{
    [view11 removeFromSuperview];
    [view1 removeFromSuperview];
    commdity.ItemCode44= itemcode;
    commdity.Itemid44= itemId;
    commdity.ItemName44= ItemName;
    commdity.ImageUrl44= ImageUrl;
    commdity.Price44= Price;
    commdity.currentSpecId44=currentSpecId;
    commdity.how44=how;
    commdity.specName44=specName;
    BusinessWhsInAddViewController *detailViewController = [[BusinessWhsInAddViewController alloc] init];
    detailViewController.titleName=@"确认出库";
    detailViewController.Whs=@"WhsOut";
    detailViewController.Type=@"WhsOutType";
    [self.navigationController pushViewController:detailViewController animated:YES];
    
}
-(void)chooseBtn2:(UIButton*)sender{
    [view11 removeFromSuperview];
    [view1 removeFromSuperview];
    
    commdity.ItemCode44= itemcode;
    commdity.Itemid44= itemId;
    commdity.ItemName44= ItemName;
    commdity.ImageUrl44= ImageUrl;
    commdity.Price44= Price;
    commdity.currentSpecId44=currentSpecId;
    commdity.how44=how;
    commdity.specName44=specName;
    BusinessWhsInAddViewController *detailViewController = [[BusinessWhsInAddViewController alloc] init];
    detailViewController.titleName=@"确认入库";
    detailViewController.Whs=@"WhsIn";
    detailViewController.Type=@"WhsInType";
    [self.navigationController pushViewController:detailViewController animated:YES];
    
}

-(void)chooseBtn4:(UIButton*)sender{
    [view11 removeFromSuperview];
    [view1 removeFromSuperview];
    commdity.ItemCode44= itemcode;
     commdity.Itemid44= itemId;
    commdity.ItemName44= ItemName;
    commdity.ImageUrl44= ImageUrl;
    commdity.Price44= Price;
    commdity.currentSpecId44=currentSpecId;
    commdity.how44=how;
    commdity.specName44=specName;
    BusinessCheckVouchAddViewController *detailViewController = [[BusinessCheckVouchAddViewController alloc] init];
    detailViewController.titleName=@"确认录入";
    detailViewController.Whs=@"CheckVouch";
    commdity.content=@"";
    commdity.content1=@"";
    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
    
    
    
}

-(void)chooseBtn5:(UIButton*)sender{
    [view11 removeFromSuperview];
    [view1 removeFromSuperview];
    BusinessOrderExtAddViewController *detailViewController = [[BusinessOrderExtAddViewController alloc] init];

    detailViewController. specNameArray=specName;
     detailViewController. itemCodeArray=itemcode;
     detailViewController. itemNameArray=ItemName;
     detailViewController. itemIdArray=itemId;
     detailViewController. specIdArray=currentSpecId;
     detailViewController. dealPriceArray=Price;
     detailViewController. quantityArray=how;
    detailViewController. headImageFullArray=ImageUrl;//图片
    NSMutableArray*  sum=[[NSMutableArray alloc]init];
    for (int i=0; i<Price.count; i++) {
        
        NSString *typeCode1 = [Price objectAtIndex:i];
        NSString *isSingle1 = [how objectAtIndex:i];
        
        [sum addObject:[NSString stringWithFormat:@"%.2f",  [typeCode1 doubleValue]*[isSingle1 doubleValue]]];
        
        
    }

    NSNumber *sum11 = [sum valueForKeyPath:@"@sum.floatValue"];
    NSString*GoldPrice=[NSString stringWithFormat:@"%@",sum11];
    detailViewController. TotalMoney=GoldPrice;//合计
    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
    
   
    
}

-(void)tijiao:(UIButton*)sender{

//    @"xiaoshoudingdan_new",


    view11=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    view11.backgroundColor=[UIColor blackColor];
    view11.alpha=0.48;
    [self .view addSubview:view11];
    
    view1=[[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight*860/1334, ScreenWidth, ScreenHeight)];
    view1.backgroundColor=[UIColor whiteColor];
    view1.alpha=1;
    [self .view addSubview:view1];
    
    
    
    
    UILabel*liness=[[UILabel alloc]initWithFrame:CGRectMake(15, 25, ScreenWidth-30, 0.35)];
    liness.backgroundColor=qianhuicolor;
    [view1 addSubview:liness];
    
    UILabel*zhuying=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2-30, 15, 60, 14)];
    zhuying.text=@"提交到";
    zhuying.textAlignment=NSTextAlignmentCenter;
    zhuying.textColor=zhonghuiColor;
    zhuying.backgroundColor=[UIColor whiteColor];
    zhuying.font=[UIFont systemFontOfSize:14];
    [view1 addSubview:zhuying];
   
    
    
    UIImageView *_xianview1 = [[UIImageView alloc]initWithFrame:CGRectMake(15,260*ScreenHeight/1334, ScreenWidth-30, 0.5)];
    _xianview1.image=[UIImage imageNamed:@"hengxian"];
    [view1 addSubview:_xianview1];
    

    
    UIButton*cardBtn22 = [[UIButton alloc]init];
    cardBtn22.frame = CGRectMake(0,170*ScreenHeight/1334, ScreenWidth/4,14);
    [cardBtn22 setTitle:@"陈列" forState:UIControlStateNormal];
    cardBtn22.titleLabel.textAlignment=NSTextAlignmentCenter;
    cardBtn22.titleLabel.font = [UIFont systemFontOfSize: 14];
    [cardBtn22 setTitleColor:qianheicolor forState:UIControlStateNormal];
    [cardBtn22 addTarget:self action:@selector(chooseBtn1:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:cardBtn22];
    
    UIButton*cardBtn = [[UIButton alloc]init];
    cardBtn.frame = CGRectMake(0,100*ScreenHeight/1334, ScreenWidth/4,15);
    [cardBtn setTitle:@"" forState:UIControlStateNormal];
    cardBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
    cardBtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [cardBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [cardBtn addTarget:self action:@selector(chooseBtn1:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:cardBtn];
   
    UIImage *img=[UIImage imageNamed:@"yangpinchenlie"];
    UIImage *tinted = [img rt_tintedImageWithColor:luseColor ];
    UIButton*touBtn3 = [[UIButton alloc]init];
    touBtn3.frame = CGRectMake(0,65*ScreenHeight/1334,60*ScreenWidth/750,60*ScreenWidth/750);
    touBtn3.center=cardBtn.center;
    [touBtn3 setImage:tinted forState:UIControlStateNormal];
    [touBtn3 addTarget:self action:@selector(chooseBtn1:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:touBtn3];
    
    
   
    
    UIButton*cardBtn222 = [[UIButton alloc]init];
    cardBtn222.frame = CGRectMake(ScreenWidth/4,170*ScreenHeight/1334, ScreenWidth/4,14);
    [cardBtn222 setTitle:@"入库" forState:UIControlStateNormal];
    cardBtn222.titleLabel.textAlignment=NSTextAlignmentCenter;
    cardBtn222.titleLabel.font = [UIFont systemFontOfSize: 14];
    [cardBtn222 setTitleColor:qianheicolor forState:UIControlStateNormal];
    [cardBtn222 addTarget:self action:@selector(chooseBtn2:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:cardBtn222];
    UIButton*cardBtn1 = [[UIButton alloc]init];
    cardBtn1.frame = CGRectMake(ScreenWidth/4,100*ScreenHeight/1334, ScreenWidth/4,15);
    [cardBtn1 setTitle:@"" forState:UIControlStateNormal];
    cardBtn1.titleLabel.textAlignment=NSTextAlignmentCenter;
    cardBtn1.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [cardBtn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [cardBtn1 addTarget:self action:@selector(chooseBtn2:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:cardBtn1];
    UIImage *img1=[UIImage imageNamed:@"shangpinruku"];
    
    UIImage *tinted1 = [img1 rt_tintedImageWithColor:luseColor ];

    UIButton*touBtn1 = [[UIButton alloc]init];
    touBtn1.frame = CGRectMake(ScreenWidth/4,65*ScreenHeight/1334,60*ScreenWidth/750,60*ScreenWidth/750);
    touBtn1.center=cardBtn1.center;
    [touBtn1 setImage:tinted1 forState:UIControlStateNormal];
    [touBtn1 addTarget:self action:@selector(chooseBtn2:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:touBtn1];
    
    
    
    
    UIButton*cardBtn333 = [[UIButton alloc]init];
    cardBtn333.frame = CGRectMake(ScreenWidth/4*2,170*ScreenHeight/1334, ScreenWidth/4,14);
    [cardBtn333 setTitle:@"出库" forState:UIControlStateNormal];
    cardBtn333.titleLabel.textAlignment=NSTextAlignmentCenter;
    cardBtn333.titleLabel.font = [UIFont systemFontOfSize: 14];
    [cardBtn333 setTitleColor:qianheicolor forState:UIControlStateNormal];
    [cardBtn333 addTarget:self action:@selector(chooseBtn3:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:cardBtn333];
    
    UIButton*cardBtn2 = [[UIButton alloc]init];
    cardBtn2.frame = CGRectMake(ScreenWidth/4*2,100*ScreenHeight/1334, ScreenWidth/4,15);
    [cardBtn2 setTitle:@"" forState:UIControlStateNormal];
    cardBtn2.titleLabel.textAlignment=NSTextAlignmentCenter;
    cardBtn2.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [cardBtn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [cardBtn2 addTarget:self action:@selector(chooseBtn3:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:cardBtn2];
    UIImage *img2=[UIImage imageNamed:@"shangpinchuku"];
    
    UIImage *tinted2 = [img2 rt_tintedImageWithColor:luseColor ];
    UIButton*touBtn2 = [[UIButton alloc]init];
    touBtn2.frame = CGRectMake(ScreenWidth/4*2,65*ScreenHeight/1334,60*ScreenWidth/750,60*ScreenWidth/750);
    touBtn2.center=cardBtn2.center;
    [touBtn2 setImage:tinted2 forState:UIControlStateNormal];
    [touBtn2 addTarget:self action:@selector(chooseBtn3:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:touBtn2];
    
    
    UIButton*cardBtn444 = [[UIButton alloc]init];
    cardBtn444.frame = CGRectMake(ScreenWidth/4*3,170*ScreenHeight/1334, ScreenWidth/4,14);
    [cardBtn444 setTitle:@"盘点" forState:UIControlStateNormal];
    cardBtn444.titleLabel.textAlignment=NSTextAlignmentCenter;
    cardBtn444.titleLabel.font = [UIFont systemFontOfSize: 14];
    [cardBtn444 setTitleColor:qianheicolor forState:UIControlStateNormal];
    [cardBtn444 addTarget:self action:@selector(chooseBtn4:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:cardBtn444];
    UIButton*cardBtn4 = [[UIButton alloc]init];
    cardBtn4.frame = CGRectMake(ScreenWidth/4*3,100*ScreenHeight/1334, ScreenWidth/4,15);
    [cardBtn4 setTitle:@"" forState:UIControlStateNormal];
    cardBtn4.titleLabel.textAlignment=NSTextAlignmentCenter;
    cardBtn4.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [cardBtn4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [cardBtn4 addTarget:self action:@selector(chooseBtn4:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:cardBtn4];
    UIImage *img3=[UIImage imageNamed:@"kucunpandian"];
    
    UIImage *tinted3 = [img3 rt_tintedImageWithColor:luseColor ];
    UIButton*touBtn4 = [[UIButton alloc]init];
    touBtn4.frame = CGRectMake(ScreenWidth/4*3,65*ScreenHeight/1334,60*ScreenWidth/750,60*ScreenWidth/750);
    touBtn4.center=cardBtn4.center;
    [touBtn4 setImage:tinted3 forState:UIControlStateNormal];
    [touBtn4 addTarget:self action:@selector(chooseBtn4:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:touBtn4];
    
    
    
    
    
    UIButton*dingdanBtn = [[UIButton alloc]init];
    dingdanBtn.frame = CGRectMake(0,370*ScreenHeight/1334, ScreenWidth/4,14);
    [dingdanBtn setTitle:@"订单" forState:UIControlStateNormal];
    dingdanBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
    dingdanBtn.titleLabel.font = [UIFont systemFontOfSize: 14];
    [dingdanBtn setTitleColor:qianheicolor forState:UIControlStateNormal];
    [dingdanBtn addTarget:self action:@selector(chooseBtn5:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:dingdanBtn];
    
    UIButton*dingdanBtn1 = [[UIButton alloc]init];
    dingdanBtn1.frame = CGRectMake(0,300*ScreenHeight/1334, ScreenWidth/4,15);
    [dingdanBtn1 setTitle:@"" forState:UIControlStateNormal];
    dingdanBtn1.titleLabel.textAlignment=NSTextAlignmentCenter;
    dingdanBtn1.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [dingdanBtn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [dingdanBtn1 addTarget:self action:@selector(chooseBtn5:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:dingdanBtn1];
    
    UIImage *dingdanBtn1img=[UIImage imageNamed:@"xiaoshoudingdan"];
    UIImage *dingdanBtn1imgtinted = [dingdanBtn1img rt_tintedImageWithColor:luseColor];
    UIButton*dingdantouBtn3 = [[UIButton alloc]init];
    dingdantouBtn3.frame = CGRectMake(0,265*ScreenHeight/1334,60*ScreenWidth/750,60*ScreenWidth/750);
    dingdantouBtn3.center=dingdanBtn1.center;
    [dingdantouBtn3 setImage:dingdanBtn1imgtinted forState:UIControlStateNormal];
    [dingdantouBtn3 addTarget:self action:@selector(chooseBtn5:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:dingdantouBtn3];

    
    // 手势
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [view11 addGestureRecognizer:singleFingerOne];
    
    
}

- (void)closeKeyBoad{
    [view1 removeFromSuperview];
    [view11 removeFromSuperview];
    
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
